var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    issuccessMask: false,
    // 发车遮罩层
    isdispatcCar: false,
  },

  // 上传配送清单图
  dispatcCar() {
    wx.navigateTo({
      url: '/supervisor/pages/deliveryList/deliveryList?orderId=' + this.data.orderId+'&&orderDeliverId='+this.data.orderDeliverId,
    })
  },
// 查看完整项目
  goorderdectio(){
    wx.navigateTo({
      url: '/pages/projectDetails/projectDetails?orderId='+this.data.orderId,
    })
  },

  fakeCallback() {},

  // 项目详情接口
  getOrderDetails() {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getOrderDetails',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        // userId: 1569562832576524288,
        orderId: t.data.orderId,
      },
      success: res => {
        wx.hideLoading();
        let orderObj = this.data.orderObj
        let projectOrder = res.data.projectOrder
        console.log(res)
        orderObj.projectCity = projectOrder.projectCity
        orderObj.projectName = projectOrder.projectName
        orderObj.projectLayout = projectOrder.projectLayout
        orderObj.projectSize = projectOrder.projectSize
        orderObj.projectArea = projectOrder.projectArea
        orderObj.customerName = projectOrder.customerName
        orderObj.customerPhone = projectOrder.customerPhone
        orderObj.projectAddress = projectOrder.projectAddress
        orderObj.projectName = projectOrder.projectName
        let deliverList = res.data.deliverList
        orderObj.driverName = deliverList[0].driverName
        orderObj.driverMobile = deliverList[0].driverMobile
        orderObj.workerName = deliverList[0].workerName
        orderObj.workerMobile = deliverList[0].workerMobile
        orderObj.leaveDate = deliverList[0].leaveDate
        orderObj.serviceDate = deliverList[0].serviceDate
        orderObj.deliverExplain = deliverList[0].deliverExplain
        let productList = deliverList[0].deliverProductList.split(",").map(item => app.globalData.Imageurl + item)
        let packAtlas = deliverList[0].packAtlas.split(",").map(item => app.globalData.Imageurl + item)
   
        if(deliverList[0].checkDeliverProductList!=''){
          let checkDeliverProductList=deliverList[0].checkDeliverProductList.split(",").map(item => app.globalData.Imageurl + item)
          let checkPackAtlas=deliverList[0].checkPackAtlas.split(",").map(item => app.globalData.Imageurl + item)
          this.setData({
            todo:'previewDeparture',
            checkDeliverProductList:checkDeliverProductList,
            checkPackAtlas:checkPackAtlas
          })

        }else{
          this.setData({
            todo:'Delivery'
          })
        }
        // let checkProductList=





        this.setData({
          productList: productList,
          packAtlas: packAtlas,
          orderDeliverId:res.data.deliverList[0].id
        })
        t.setData({
          orderObj: orderObj
        })
      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },



  // 18.上传配送清单

  saveOrderDeliver() {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'saveOrderDeliver',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        // userId: 1569562832576524288,
        orderId: t.data.orderId,
        token: t.data.token,
        productList: t.data.orderObj.productList.join(","),
        packAtlas: t.data.orderObj.packAtlas.join(","),
        deliverExplain: t.data.orderObj.deliverExplain,
        leaveDate: t.data.orderObj.leaveDate,
        serviceDate: t.data.orderObj.serviceDate,
        driverName: t.data.orderObj.driverName,
        driverMobile: t.data.orderObj.driverMobile,
        workerName: t.data.orderObj.workerName,
        workerMobile: t.data.orderObj.workerMobile,
      },
      success: res => {
        wx.hideLoading()
      if(res.data.result==0){
        this.setData({
          isdispatcCar: true
        })
      }else{
        wx.showToast({
          title: res.data.message,
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
        t.setData({
          token:app.token
        })
      }

      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
          icon: 'none', //图标
        })
      }
    })
  },
// 查看图片
priview(e){
    let current=e.currentTarget.dataset.current
    let urls=e.currentTarget.dataset.urls
    wx.previewImage({
      urls: urls,
      current:current
    })

},


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      orderId: options.orderId,
      orderObj: {},
    })
    this.getOrderDetails()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  onPageScroll(e) {

    this.setData({
      bigscrooltop: e.scrollTop
    })

  }
})